{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% macro render_form(form, permissions, td_type, admin, admin_configuration, object) %}
    <form class="form-horizontal"
          action="{{ admin.generateUrl('acl', {(admin.idParameter): admin.id(object), 'uniqid': admin.uniqid, 'subclass': app.request.attributes.get('subclass', app.request.query.get('subclass', app.request.request.get('subclass')))}) }}"
          {% if form.vars.multipart %} enctype="multipart/form-data"{% endif %}
          method="POST"
            {% if not admin_configuration.getOption('html5_validate') %}novalidate="novalidate"{% endif %}
            >

        {{ include('@SonataAdmin/Helper/render_form_dismissable_errors.html.twig') }}

        <div class="box box-success">
            <div class="body table-responsive no-padding">
                <table class="table">
                    <colgroup>
                        <col style="width: 100%;"/>
                        {% for permission in permissions %}
                            <col/>
                        {% endfor %}
                    </colgroup>

                    {% for child in form.children|filter(child => child.vars.name != '_token') %}
                        {% if loop.index0 == 0 or loop.index0 % 10 == 0 %}
                            <tr>
                                <th>{{ td_type|trans({}, 'SonataAdminBundle') }}</th>
                                {% for permission in permissions %}
                                    <th class="text-right">{{ permission }}</th>
                                {% endfor %}
                            </tr>
                        {% endif %}

                        <tr>
                            <td>
                                {% set typeChild = child['role'] is defined ? child['role'] : child['user'] %}
                                {{ typeChild.vars.value }}
                                {{ form_widget(typeChild) }}
                            </td>
                            {% for permission in permissions %}
                                <td class="text-right">{{ form_widget(child[permission], { label: false }) }}</td>
                            {% endfor %}
                        </tr>
                    {% endfor %}
                </table>
            </div>
        </div>

        {{ form_row(form._token) }}

        <div class="well well-small form-actions">
            <input class="btn btn-primary" type="submit" name="btn_create_and_edit" value="{{ 'btn_update_acl'|trans({}, 'SonataAdminBundle') }}">
        </div>
    </form>
{% endmacro %}
